#!/usr/bin/env bash

include "test.sh"

export regex_id="[a-zA-Z_][a-zA-Z_0-9]*"
export regex_id2="[a-zA-Z_-][a-zA-Z_0-9-]*"
export regex_issue="I[A-Z0-9]*"
export regex_dec_integer="^-?([1-9][0-9]*|0)$"
export regex_date="[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}"
export regex_time="[0-9]{2}:[0-9]{2}"

function regex::test()
{
    local regex="$1"
    shift
    local text="$*"

    [[ "$text" =~ (^${!regex}$) ]]
}

function regex::test1()
{
    test::should_return_true  regex::test regex_id "a"
    test::should_return_true  regex::test regex_id "_"
    test::should_return_true  regex::test regex_id "A1"
    test::should_return_true  regex::test regex_id "AaA"

    test::should_return_false regex::test regex_id "1"
    test::should_return_false regex::test regex_id "-"
    test::should_return_false regex::test regex_id "_A-"
}
test::register_test regex::test1

function regex::test2()
{
    test::should_return_true  regex::test regex_id2 "a"
    test::should_return_true  regex::test regex_id2 "_"
    test::should_return_true  regex::test regex_id2 "A1"
    test::should_return_true  regex::test regex_id2 "AaA"
    test::should_return_true  regex::test regex_id2 "-"
    test::should_return_true  regex::test regex_id2 "_A-"

    test::should_return_false regex::test regex_id2 "1"
}
test::register_test regex::test2

function regex::test3()
{
    test::should_return_true  regex::test regex_date "0123-15-65"
    test::should_return_true  regex::test regex_date "3456-1-12"
    test::should_return_true  regex::test regex_date "1900-1-1"

    test::should_return_false regex::test regex_date "123-1-1"
    test::should_return_false regex::test regex_date "1234-564-2"
    test::should_return_false regex::test regex_date "1234-56-244"
}
test::register_test regex::test3

function regex::test4()
{
    test::should_return_true  regex::test regex_time "11:22"
    test::should_return_true  regex::test regex_time "33:44"
    test::should_return_true  regex::test regex_time "01:23"

    test::should_return_false regex::test regex_time "1:23"
    test::should_return_false regex::test regex_time "23:1"
}
test::register_test regex::test4
